package test1

import (
	"fmt"
	"time"
)

type MultiPlyFunc func(int, int) int



func multiply(a, b int) int {
	return a * b
}

func multiply2(a, b int) int {
	return a << b
}

func execTime(f MultiPlyFunc) MultiPlyFunc {
	return func(a, b int) int {
		start := time.Now()
		c := f(a, b)
		end := time.Since(start)
		fmt.Printf("计算耗时 %v\n", end)
		return c
	}
}


func Test9() {
	a := 2
	b := 8
	c := multiply(a, b)
	fmt.Println(c)

	decorator := execTime(multiply)
	d := decorator(a, b)
	fmt.Println(d)

	decorator2 := execTime(multiply2)
	e := decorator2(a, b)
	fmt.Println(e)
}